﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace TinyCinema.Data
{
    public class ScheduleType:Execution
    {
        public string ID { get; set; }
        string _Name;
        public string Name { get{return _Name;}
            set 
            {
                _Name = value;
                OnPropertyChanged("Name");
            }
        }
        public static ObservableCollection<ScheduleType> lstType {get;set;}
        int _TypeIndex;
        bool IsInit = false;
        public int TypeIndex
        {
            get { 
                return _TypeIndex; }
            set
            {
                _TypeIndex = value;
                if (IsInit)
                {
                    ID = lstType[value].ID;
                    Name = lstType[value].Name;
                }
            }
        }
        public ObservableCollection<SchedulePrice> ScheduleTypePrice { get; set; }
        public ScheduleType()
        {
            TypeIndex = 0;
            IsInit = true;
        }
        public ScheduleType(string _ID)
        {
            ID = _ID;
            PutTableIntoDataSet(Tables.ScheduleType);
            var tbl = ds.Tables[Tables.ScheduleType];
            var Rows = tbl.Select();
            TypeIndex = 0;
            foreach (var row in Rows)
                if (row[ScheduleTypeTable.ID] as String == ID)
                {
                    Name = row[ScheduleTypeTable.Name] as String;
                    break;
                }
                else ++TypeIndex;

            if (lstType == null)
            {
                lstType = new ObservableCollection<ScheduleType>();
                foreach (var row in Rows)
                    lstType.Add(new ScheduleType(row[ScheduleTypeTable.ID] as string));
            }
            IsInit = true;
        }
    }
}
